home *** CD-ROM | disk | FTP | other *** search
/ Visual Cafe 3 / Visual Cafe 3.ISO / Vcafe / JFC.bin / MetalUtils.java < prev    next >
Text File  |  1998-06-30  |  5KB  |  162 lines

  1. /*
  2.  * @(#)MetalUtils.java    1.16 98/03/05
  3.  * 
  4.  * Copyright (c) 1997 Sun Microsystems, Inc. All Rights Reserved.
  5.  * 
  6.  * This software is the confidential and proprietary information of Sun
  7.  * Microsystems, Inc. ("Confidential Information").  You shall not
  8.  * disclose such Confidential Information and shall use it only in
  9.  * accordance with the terms of the license agreement you entered into
  10.  * with Sun.
  11.  * 
  12.  * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE
  13.  * SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  14.  * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
  15.  * PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR ANY DAMAGES
  16.  * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING
  17.  * THIS SOFTWARE OR ITS DERIVATIVES.
  18.  * 
  19.  */
  20.  
  21. package com.sun.java.swing.plaf.metal;
  22.  
  23. import com.sun.java.swing.plaf.*;
  24. import com.sun.java.swing.*;
  25. import java.awt.*;
  26.  
  27. /**
  28.  * This is a dumping ground for random stuff we want to use in several places.
  29.  *
  30.  * @version 1.16 03/05/98
  31.  * @author Steve Wilson
  32.  */
  33.  
  34. public class MetalUtils {
  35.  
  36.     static void drawFlush3DBorder(Graphics g, Rectangle r) {
  37.         drawFlush3DBorder(g, r.x, r.y, r.width, r.height);
  38.     }
  39.  
  40.     /**
  41.       * This draws the "Flush 3D Border" which is used throughout the Metal L&F
  42.       */
  43.     static void drawFlush3DBorder(Graphics g, int x, int y, int w, int h) {
  44.         g.translate( x, y);
  45.         g.setColor( MetalLookAndFeel.getControlDarkShadow() );
  46.     g.drawRect( 0, 0, w-2, h-2 );
  47.         g.setColor( MetalLookAndFeel.getControlHighlight() );
  48.     g.drawRect( 1, 1, w-2, h-2 );
  49.         g.setColor( MetalLookAndFeel.getControl() );
  50.     g.drawLine( 0, h-1, 1, h-2 );
  51.     g.drawLine( w-1, 0, w-2, 1 );
  52.         g.translate( -x, -y);
  53.     }
  54.  
  55.     /**
  56.       * This draws a variant "Flush 3D Border"
  57.       * It is used for things like pressed buttons.
  58.       */
  59.     static void drawPressed3DBorder(Graphics g, Rectangle r) {
  60.         drawPressed3DBorder( g, r.x, r.y, r.width, r.height );
  61.     }
  62.  
  63.     static void drawDisabledBorder(Graphics g, int x, int y, int w, int h) {
  64.         g.translate( x, y);
  65.         g.setColor( MetalLookAndFeel.getControlShadow() );
  66.     g.drawRect( 0, 0, w-1, h-1 );
  67.     }
  68.  
  69.     /**
  70.       * This draws a variant "Flush 3D Border"
  71.       * It is used for things like pressed buttons.
  72.       */
  73.     static void drawPressed3DBorder(Graphics g, int x, int y, int w, int h) {
  74.         g.translate( x, y);
  75.  
  76.         drawFlush3DBorder(g, 0, 0, w, h);
  77.  
  78.         g.setColor( MetalLookAndFeel.getControlShadow() );
  79.     g.drawLine( 1, 1, 1, h-2 );
  80.     g.drawLine( 1, 1, w-2, 1 );
  81.         g.translate( -x, -y);
  82.     }
  83.  
  84.     /**
  85.       * This draws a variant "Flush 3D Border"
  86.       * It is used for things like active toggle buttons.
  87.       * This is used rarely.
  88.       */
  89.     static void drawDark3DBorder(Graphics g, Rectangle r) {
  90.         drawDark3DBorder(g, r.x, r.y, r.width, r.height);
  91.     }
  92.  
  93.     /**
  94.       * This draws a variant "Flush 3D Border"
  95.       * It is used for things like active toggle buttons.
  96.       * This is used rarely.
  97.       */
  98.     static void drawDark3DBorder(Graphics g, int x, int y, int w, int h) {
  99.         g.translate( x, y);
  100.  
  101.         drawFlush3DBorder(g, 0, 0, w, h);
  102.  
  103.         g.setColor( MetalLookAndFeel.getControl() );
  104.     g.drawLine( 1, 1, 1, h-2 );
  105.     g.drawLine( 1, 1, w-2, 1 );
  106.         g.setColor( MetalLookAndFeel.getControlShadow() );
  107.     g.drawLine( 1, h-2, 1, h-2 );
  108.     g.drawLine( w-2, 1, w-2, 1 );
  109.         g.translate( -x, -y);
  110.     }
  111.  
  112.     static void drawButtonBorder(Graphics g, int x, int y, int w, int h, boolean active) {
  113.         if (active) {
  114.             drawActiveButtonBorder(g, x, y, w, h);        
  115.         } else {
  116.             drawFlush3DBorder(g, x, y, w, h);
  117.     }
  118.     }
  119.  
  120.     static void drawActiveButtonBorder(Graphics g, int x, int y, int w, int h) {
  121.         drawFlush3DBorder(g, x, y, w, h);
  122.         g.setColor( MetalLookAndFeel.getPrimaryControl() );
  123.     g.drawLine( x+1, y+1, x+1, h-3 );
  124.     g.drawLine( x+1, y+1, w-3, x+1 );
  125.         g.setColor( MetalLookAndFeel.getPrimaryControlDarkShadow() );
  126.     g.drawLine( x+2, h-2, w-2, h-2 );
  127.     g.drawLine( w-2, y+2, w-2, h-2 );
  128.     }
  129.  
  130.     static void drawDefaultButtonBorder(Graphics g, int x, int y, int w, int h, boolean active) {
  131.         drawButtonBorder(g, x+1, y+1, w-1, h-1, active);        
  132.         g.setColor( MetalLookAndFeel.getControlDarkShadow() );
  133.     g.drawRect( x, y, w-3, h-3 );
  134.     g.drawLine( w-2, 0, w-2, 0);
  135.     g.drawLine( 0, h-2, 0, h-2);
  136.     }
  137.  
  138.     static class TableHeaderBorder extends com.sun.java.swing.border.AbstractBorder {
  139.         protected Insets editorBorderInsets = new Insets( 2, 2, 2, 0 );
  140.  
  141.         public void paintBorder(Component c, Graphics g, int x, int y, int w, int h) {
  142.         g.translate( x, y );
  143.         
  144.         g.setColor( MetalLookAndFeel.getControlDarkShadow() );
  145.         g.drawLine( w-1, 0, w-1, h-2 );
  146.         g.drawLine( 1, h-2, w-1, h-2 );
  147.         g.setColor( MetalLookAndFeel.getControlHighlight() );
  148.         g.drawLine( 0, 0, w-2, 0 );
  149.         g.drawLine( 0, 0, 0, h-3 );
  150.         g.setColor( MetalLookAndFeel.getControlShadow() );
  151.         g.drawLine( 0, h-1, w-1, h-1 );
  152.  
  153.  
  154.         g.translate( -x, -y );
  155.     }
  156.  
  157.         public Insets getBorderInsets( Component c ) {
  158.         return editorBorderInsets;
  159.     }
  160.     }
  161. }
  162.